package com.dy.lock.screen.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dy.lock.screen.constants.Constant;
import com.dy.lock.screen.dao.CommonCommentDao;
import com.dy.lock.screen.pojo.CommonCommentInfo;
import com.dy.lock.screen.service.CommonCommentService;
import com.dy.lock.screen.utils.CommonUtil;
import com.dy.lock.screen.vo.CommonCommentLikeVo;

@Service("commonCommentService")
public class CommonCommentServiceImpl implements CommonCommentService {

	@Resource(name = "commonCommentDao")
	private CommonCommentDao commonCommentDao;

	@Override
	public List<CommonCommentInfo> queryPage(Map<String, Object> para) {
		List<CommonCommentInfo> list = this.commonCommentDao.queryT(para);
		return list;
	}

	@Override
	public CommonCommentInfo queryByPrimaryKey(String cid) {
		return this.commonCommentDao.queryByPrimaryKey(cid);

	}

	@Override
	public Integer queryCount(Map<String, Object> para) {
		return this.commonCommentDao.queryCount(para);
	}

	@Override
	public List<CommonCommentInfo> queryByCommentId(Map<String, Object> para) {
		List<CommonCommentInfo> list = this.commonCommentDao
				.queryByCommentId(para);
		return list;
	}

	@Override
	public int falseDelete(CommonCommentInfo commInfo) {
		// TODO Auto-generated method stub
		return this.commonCommentDao.update(commInfo);
	}

	@Override
	public String save(CommonCommentInfo commInfo) {
		commInfo.setCommonCommentId((CommonUtil.createRandomNum()));
		for (int i = 0; i < 20; i++) {
			CommonCommentInfo m = this.commonCommentDao
					.queryByPrimaryKey(commInfo.getCommonCommentId());
			if (m != null) {
				commInfo.setCommonCommentId((CommonUtil.createRandomNum()));
			} else {
				break;
			}
		}
		commInfo.setCommentTime(new Date());
		commInfo.setIsDelete(Constant.IS_NOT_DELETE);
		int re = this.commonCommentDao.insert(commInfo);
		if (re > 0) {
			return commInfo.getCommonCommentId();
		} else {
			return "";
		}
	}

	@Override
	public CommonCommentLikeVo queryDetailByPrimaryKey(String id) {
		// TODO Auto-generated method stub
		return this.commonCommentDao.queryDetailByPrimaryKey(id);
	}

}
